package com.zzg.mybatis.generator.plugins;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;

import java.sql.Types;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * sql type和java type转换
 * @author : liuxiu
 * @date : 2020/1/10 16:48
 * @since : 1.0
 */
public class SqlTypeJavaTypeConvert extends JavaTypeResolverDefaultImpl {

    @Override
    protected FullyQualifiedJavaType overrideDefaultType(IntrospectedColumn column, FullyQualifiedJavaType defaultType) {
        FullyQualifiedJavaType answer = defaultType;
        String bitToInteger = this.properties.getProperty("bitToInteger");
        String tinyintToInteger = this.properties.getProperty("tinyintToInteger");
        switch (column.getJdbcType()) {
            case Types.BIT:
                if ("true".equalsIgnoreCase(bitToInteger)) {
                    answer = new FullyQualifiedJavaType(Integer.class.getName());
                }
                break;
            case Types.TINYINT:
                if ("true".equalsIgnoreCase(tinyintToInteger)) {
                    answer = new FullyQualifiedJavaType(Integer.class.getName());
                }
                break;
            default:
                break;
        }

        return answer;
    }
}
